#!/bin/bash
	
	MUSIC_DIR=~/Music/
	COVER=/tmp/cover2.png
    

	NCMP=$(mpc | grep "^\[playing\]" | awk '{print $1}')

    if [ "$NCMP" = "[playing]" ]; then
        album="$(mpc --format %album% current)"
        file="$(mpc --format %file% current)"
        album_dir="${file%/*}"
        [[ -z "$album_dir" ]] && exit 1
        album_dir="$MUSIC_DIR/$album_dir"

        covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)" \; )"
        src="$(echo -n "$covers" | head -n1)"
        if [[ "$src" == "" ]]; then
            rm -f "$COVER"
            echo "NOCOVER"
        else
            rm -f "$COVER"
            cp "$src" "$COVER"
            echo "COVER"
        
            
        fi
    fi